package 无重复字符的最长子串;

import java.util.ArrayList;
import java.util.List;

public class Solution {


    public static void main(String[] args) {

        Solution solution = new Solution();
        int count = solution.lengthOfLongestSubstring("abcabcbb");
//        int count = solution.lengthOfLongestSubstring(" ");

        System.out.println(count);

    }

    public int lengthOfLongestSubstring(String s) {


        char[] chars = s.toCharArray();

        List list = new ArrayList<>();

        int max = 0;
        for (int i = 0; i < chars.length; i++) {
            char aChar = chars[i];
            int index = list.indexOf(aChar);

            list.add(aChar);
            if(index != -1){
                list = list.subList(index+1,list.size());
            }

            int length = list.size() - 1 - index;
            max = max > length ? max : length;
        }



        return max ;
    }
}
